package cn.meibang.aggragation.beauty.controller;

import cn.apestar.agg.common.security.BaseAuthController;
import cn.apestar.agg.common.security.annotation.NoLoginRequired;
import cn.meibang.common.beauty.api.IBeautyConsultationOrderAPIService;
import cn.meibang.common.beauty.provider.request.ListOrderUserRequest;
import cn.meibang.common.beauty.provider.request.SubmitOrderRequest;
import cn.meibang.common.beauty.provider.response.BcoResponse;
import cn.meibang.common.beauty.provider.response.BcoUserResponse;
import cn.meibang.common.beauty.provider.response.SubmitOrderResponse;
import cn.meibang.common.beauty.provider.response.UserOrderResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by admin on 2017-5-30.
 */
@RestController
@RequestMapping("/bco")
public class BcoController extends BaseAuthController {

    @Autowired
    IBeautyConsultationOrderAPIService beautyConsultationOrderAPIService;

    @RequestMapping(value = "/getOrderById/{id}")
    public BcoResponse getOrderById(@PathVariable("id") Long id) {
        return beautyConsultationOrderAPIService.getOrderById(id);
    }

    @RequestMapping(value = "/getAllValidOrder")
    public List<BcoResponse> getAllValidOrder() {
        return beautyConsultationOrderAPIService.getAllValidOrder();
    }

    @RequestMapping(value = "/submitOrder", method = RequestMethod.POST)
    public Object submitOrder(@RequestBody SubmitOrderRequest request, @RequestHeader(value = "ticket") String ticket) {
        // 美邦当前登录的用户ID为咨询顾问的ID
        request.setConsultantId(getCurrentUserId());
        return beautyConsultationOrderAPIService.submitOrder(request, ticket);
    }

    @RequestMapping(value = "/getLatestSubmitOrder")
    public SubmitOrderResponse getLatestSubmitOrder(@RequestParam("orderId") Long orderId,
                                                    @RequestParam(value = "userId", required = false) Long userId,
                                                    @RequestParam(value = "openid", required = false) String openid) {
        return beautyConsultationOrderAPIService.getLatestSubmitOrder(orderId, userId, openid);
    }

    /**
     * 获取用户最新的所有咨询单的详情
     *
     * @param userId 订单列表的ID
     * @return
     */
    @RequestMapping(value = "/getUserAnswerDetail")
    public List<UserOrderResponse> getUserAnswerDetail(@RequestParam(value = "user_id", required = false) Long userId,
                                                       @RequestParam(value = "openid", required = false) String openid) {
        return beautyConsultationOrderAPIService.getUserOrderResponse(userId, openid);
    }

    /**
     * 获取某个技师所有的咨询单
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/listOrderUser")
    public List<BcoUserResponse> listOrderUser(@RequestBody ListOrderUserRequest request, @RequestHeader(value = "ticket") String ticket) {
        return beautyConsultationOrderAPIService.listOrderUser(request, getCurrentUserId(), ticket);
    }

    @RequestMapping(value = "/feedbackDeal/{id}")
    @NoLoginRequired
    public void feedbackDeal(@PathVariable("id") Long id) {
        beautyConsultationOrderAPIService.feedbackDeal(id);
    }

}
